package com.xxxx.file.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by stfu
 * 2021-08-13 18:43
 */
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {

    @Value("${file.path}")
    private String FILE_PATH;

    /**
     * SpringBoot静态资源配置, 静态资源包含图片, CSS, JS等
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //  addResourceHandler("/f/**") 拦截请求访问本地资源, 所有/qy/开头的请求,
        //  都会去后面配置的路径"file:D:/file/stfu-course"查找资源(真实地址前必须加上 "file:")
        registry.addResourceHandler("/f/**").addResourceLocations("file:" + FILE_PATH);
    }

    //  http://127.0.0.1:9003/file/f/teacher/3edCVIwx-zxc1.jpg
}
